package main

//link: https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/
func main() {

}

func removeDuplicates(nums []int) int {
	left, right := 0, 0
	index := 0
	for right < len(nums) {
		for right < len(nums) && nums[left] == nums[right] {
			right++
		}
		if right-left == 1 {
			nums[index] = nums[left]
			index++
		}
		if right-left >= 2 {
			nums[index] = nums[left]
			index++
			nums[index] = nums[left]
			index++
		}
		left = right
	}
	return index
}
